<template>
  <ge-page id="ge-page" :safeAreaBottom="false">
    <view class="My">
      <view id="BuildingApplication">
        <view class="SQList" ref="SQList" v-show="isShow1">
          <van-tabs ref="tabs" v-model="active" @click="handleclickto">
            <van-tab title="我的待办">
              <view class="BuildingApplicationLeft">
                <ul>
                  <view style="clear: both">
                    <li v-show="contentData2.length > 0" v-for="(item, index) in contentData2"
                      @click="contentDataClick(item)" :key="index">
                      <p style="font-weight: bold; height: 28px">
                        <span style="float: left">{{ item.NODE_NAME }}</span>
                        <span style="float: right">{{ item.SQR }}</span>
                      </p>
                      <p style="font-size: 14px; color: #848484; height: 28px">
                        <span style="float: left">进度：{{ item.PROC_NAME }}</span>
                        <span style="float: right">{{ item.JDJGMC }}</span>
                      </p>
                      <p style="font-size: 14px; color: #848484; height: 20px">
                        <span style="float: left">地址：{{
                        item.SSC_CITYNAME ? item.SSC_CITYNAME : "暂无数据"
                        }}</span>
                        <span style="float: right">委托时间：{{ item.WTSJ || "暂无数据" }}</span>
                      </p>
                    </li>
                  </view>
                  <view style="height: 60vh; text-align: center; padding-top: 20vh" v-show="noData">
                    <view style="margin-bottom: 10px">
                      <img src="https://nfzjszlb.jst.zj.gov.cn/serverfile/zheliban/icon/DSF/50.png" />
                    </view>
                    <view>暂无数据</view>
                  </view>
                </ul>
              </view>
            </van-tab>
            <van-tab title="申请记录">
              <view id="shenQing" ref="shenQing">
                <ul>
                  <li v-show="contentData3.length > 0" v-for="(item, index) in contentData3" @click="handle(item)"
                    :key="index">
                    <p style="font-weight: bold; height: 30px">
                      <span style="float: left">{{ item.NODE_NAME }}</span>
                      <span style="float: right">{{ item.SQR }}</span>
                    </p>
                    <p style="font-size: 14px; color: #848484; height: 30px">
                      <span style="float: left">进度：{{ item.PROC_NAME }}</span>
                      <span style="float: right">{{ item.JDJGMC }}</span>
                    </p>
                    <p style="font-size: 14px; color: #848484; height: 30px">
                      <span style="float: left">地址：{{
                      item.SSC_CITYNAME ? item.SSC_CITYNAME : "暂无数据"
                      }}</span>
                      <span style="float: right">申请时间：{{ item.CREATETIME || "暂无数据" }}</span>
                    </p>
                  </li>
                  <view style="height: 60vh; text-align: center; padding-top: 20vh" v-show="contentData3.length == 0">
                    <view style="margin-bottom: 10px">
                      <img src="https://nfzjszlb.jst.zj.gov.cn/serverfile/zheliban/icon/DSF/50.png" />
                    </view>
                    <view>暂无数据</view>
                  </view>
                </ul>
              </view>
            </van-tab>
          </van-tabs>
          <view>
            <u-modal :show="isShow" confirmText="接单" cancelText="拒绝" :showCancelButton="true" @cancel="cancel11"
              :title="title" @confirm="confirm11" :closeOnClickOverlay="true" :content="content"></u-modal>
            <u-modal :show="isShow12" :showCancelButton="true" @cancel="cancel12" :title="title" @confirm="confirm12"
              :closeOnClickOverlay="true" :content="content1"></u-modal>
          </view>
        </view>
      </view>
      <u-toast ref="uToast"></u-toast>
    </view>
    <view>
      <!-- <u-popup
        v-model="showJJLY"
        mode="center"
        @close="closeJJLY"
        @open="openJJLY"
      >
        <view>
          <text>{{ contentJJLY }}</text>
        </view>
      </u-popup> -->
      <view>
        <u-modal :show="showJJLY" @confirm="openJJLY" title="拒绝理由" :content="contentJJLY"></u-modal>
      </view>
      <view>
        <u-modal :show="reload" @confirm="openreload" title="提示" content="请重新选择鉴定公司"></u-modal>
      </view>
    </view>
  </ge-page>
</template>

<script>
import qs from "qs";
import { ECALoadGridData, ECAExecProcedure,FileServer } from "@/common/utils/api.js";
export default {
  data() {
    return {
      noData: false,
      reload: false,
      ifOnShow: false,
      contentJJLY: "",
      showJJLY: false,
      ISGJ: false,
      isShow1: false,
      isShow12: false,
      handleGoto: 0,
      nowIndex: 1,
      newItem: [],
      isShow: false,
      title: "提示",
      tableData: {},
      content: "请选择是否接单",
      content1: "请重新选择鉴定单位",
      contentData3: [
        // {
        //   SQR: "蒋海燕",
        //   NODE_NAME: "浙江政欣工程设计有限公司",
        //   PROC_NAME: "签合同",
        //   JDJGMC: "2022-08-19",
        //   SSC_CITYNAME: "浙江省杭州市临安区玲珑街道陈村村",
        // },
      ],
      //备用
      contentData6: [
        {
          SQR: "蒋海燕",
          NODE_NAME: "浙江政欣工程设计有限公司",
          PROC_NAME: "签合同",
          JDJGMC: "2022-08-19",
          SSC_CITYNAME: "浙江省杭州市西湖区北山街道上保社区",
        },
      ],
      active: "first",
      contentData2: [
        // {
        //   SQR: "蒋海燕",
        //   NODE_NAME: "浙江政欣工程设计有限公司",
        //   PROC_NAME: "签合同",
        //   JDJGMC: "2022-08-19",
        //   SSC_CITYNAME: "浙江省杭州市临安区玲珑街道陈村村",
        // },
      ],
      contentData8: [
        {
          SQR: "蒋海燕",
          NODE_NAME: "浙江政欣工程设计有限公司",
          PROC_NAME: "鉴定公司拒绝接单",
          JDJGMC: "2022-08-19",
          SSC_CITYNAME: "浙江省杭州市临安区玲珑街道陈村村",
        },
        {
          SQR: "蒋海燕",
          NODE_NAME: "浙江政欣工程设计有限公司",
          PROC_NAME: "签合同",
          JDJGMC: "2022-08-19",
          SSC_CITYNAME: "浙江省杭州市临安区玲珑街道陈村村",
        },
      ],
      text1: {
        title: "提示",
        message: "请确认是否需要更换工匠?",
        btn: {
          okText: "确定",
          cancelText: "取消",
        },
      },
      row: {},
      shoulm1: false,
      contentData1: [
        {
          name: "我要建房申请",
          num: 0,
        },
        {
          name: "我的贷款申请",
          num: 0,
        },
        {
          name: "我购买的保险",
          num: 0,
        },
        {
          name: "我要改扩建申请",
          num: 0,
        },
        {
          name: "我要危改申请",
          num: 0,
        },
        {
          name: "我要流转申请",
          num: 0,
        },
        {
          name: "我要办理不动产权证申请",
          num: 0,
        },
      ],
      shoulm1: false,
    };
  },
  watch: {
    isShow1(val) {
      this.$nextTick(() => {
        this.$refs.tabs.resize();
      });
    },
  },
  onHide() {
    this.ifOnShow = true
  },
  onShow() {
    this.getDataed();
    if (uni.getStorageSync("userType") == "农户") {
      this.getData();
    } else {
      this.getDataQY();
    }
  },
  onLoad() {
    this.isShow1 = false;
    this.$nextTick(() => {
      this.isShow1 = true;
    });
    if (ZWJSBridge) {
      ZWJSBridge.setTitle({
        title: "待办",
      })
        .then((res) => { })
        .catch((err) => { });
    }
    if (uni.getStorageSync("name") == "房屋一") {
    } else {
      console.log("2222");
      // this.contentData2 = this.contentData6;
    }
  },
  mounted() {
    this.isShow1 = false;
    this.getDataed();
    this.$nextTick(() => {
      this.isShow1 = true;
    });
    console.log(this.isShow1);
    if (uni.getStorageSync("name") == "房屋一") {
    } else {
      console.log("2222");
      // this.contentData2 = this.contentData6;
    }
    if (uni.getStorageSync("userType") == "农户") {
      this.getData();
    } else {
      this.getDataQY();
    }
  },
  methods: {
    handleclickto() { },
    showToast(params) {
      this.$refs.uToast.show({
        message: "已拒绝接单",
        type: "error",
      });
    },
    openreload() {
      this.reload = false
      //跳转去更新鉴定公司
      uni.setStorageSync('reload', JSON.stringify(this.row))
      uni.navigateTo({
        url: "/pages/Authentication/Authentication"
      });
    },
    //是否接单
    async isJieDan(data) {
      let formData = new FormData();
      let dtParams = [{ i_type: 2, i_ht_type: 5, i_pkid: 6 }];
      formData.append("procName", "up_ht_by_pkid");
      formData.append("token", uni.getStorageSync("token"));
      formData.append("dtParams", JSON.stringify(dtParams));
      const res = await ECAExecProcedure(formData);
      if (res.Success) {
        //更新成功
      }
    },
    confirm11() {
      //i_type=2来更新这个字段IF_TYJD
      this.isJieDan(5);
      uni.navigateTo({
        url: "/pages/MyTodoList/MyTodoList?data=" + JSON.stringify(this.row),
        animationType: "fade-in",
      });
      this.isShow = false;
    },
    cancel11() {
      this.isShow = false;
      this.contentData2[0].PROC_NAME = "鉴定公司拒绝接单";
      /**
       * 拒绝的话，需要填写拒绝理由。
       */
      uni.navigateTo({
        url: "/pages/Refused/Refused?data=" + JSON.stringify(this.row),
      });
    },
    confirm12() {
      uni.navigateTo({
        url: "/pages/applyAppraisal/applyAppraisal",
        animationType: "fade-in",
      });
      this.contentData2[0].PROC_NAME = "签合同";
      this.isShow12 = false;
    },
    closeJJLY() { },
    openJJLY() {
      this.showJJLY = false;
      //弹窗提示重新选择
      this.reload = true
    },
    cancel12() {
      this.isShow12 = false;
    },
    showToast7(params) {
      this.$refs.uToast.show({
        message: "当前环节不需要处理！",
        type: "error",
      });
    },
    async ECAExecProcedure1() {
      let time = Date.now();
      let data = {
        procName: "get_fileGuid_by_rowGuid",
        dtParams: JSON.stringify([{ "i_row_guid": this.row.ROW_GUID,"i_group_guid":"8ae061e7-ad06-48ec-bae4-5ba0732a4d77" }]),
        time: time,
        viewParameter: {},
      };
      const res = await ECAExecProcedure(data)
      return res
    },
   async contentDataClick(data) {
      this.row = data;
      //根据当前登录的人员角色判断是个人件还是企业件
      if (data.IF_QDHT_JG != null) {
        //农户需要看合同直接预览
       const res1 = await this.ECAExecProcedure1()
       uni.setStorageSync('fileurl',res1.Data[0].ROW_GUID)
       uni.navigateTo({
          url: "/pages/pdfView/pdfView",
        });
      } else {
        if (
          uni.getStorageSync("isPer") == 0 ||
          uni.getStorageSync("isPer") == 1
        ) {
          if (data.NODE_GUID == "{91A7427E-13ED-489F-AF84-5B0C9250855C}") {
            uni.navigateTo({
              url: "/pages/MyTodoList/MyTodoList?data=" + JSON.stringify(data),
              animationType: "fade-in",
            });
          }
          //如果鉴定公司已经拒绝
          else if (data.JJLY != null) {
            this.showJJLY = true;
            this.contentJJLY = data.JJLY;
            console.log(data.JJLY, "k");
          } else {
            this.showToast7();
            return;
          }
        } else if (uni.getStorageSync("isPer") == 2) {
          if (
            data.NODE_GUID == "{FA54F190-31A8-41A1-9CA8-798339A5FC68}" ||
            data.NODE_GUID == "{2C47F8CD-2BAB-4DA2-B5E5-87E6178E519A}"
          ) {
            this.isShow = true;
          } else if (data.NODE_GUID == "{C598953F-7F23-4E8D-AA5B-7B68C71797E8}") {
            uni.navigateTo({
              url: "/pages/MyTodoList/MyTodoList?data=" + JSON.stringify(data),
              animationType: "fade-in",
            });
          } else if (data.JJLY != null) {
            this.showJJLY = true;
            this.contentJJLY = data.JJLY;
          } else {
            this.showToast7();
            return;
          }
        }
      }

    },
    async getData() {
      //个人版
      let searchObject = [];
      let data = {
        dataGuid: "2557f4c7-9f3c-4333-a26b-76a228909ce4",
        searchObject: JSON.stringify(searchObject),
        bizGuid: "82c1d3c7-f56a-4414-8382-f06e13a9772e",
      };
      const res = await ECALoadGridData(data);
      this.contentData2 = res.Data;
      if (this.contentData2.length == 0) {
        this.noData = true;
      }
    },
    async getDataQY() {
      //企业
      let searchObject = [];
      let data = {
        dataGuid: "73b412ca-1dcb-4a0f-ae36-54998e4c49e2",
        searchObject: JSON.stringify(searchObject),
        bizGuid: "82c1d3c7-f56a-4414-8382-f06e13a9772e",
      };
      const res = await ECALoadGridData(data);
      this.contentData2 = res.Data;
      if (this.contentData2.length == 0) {
        this.noData = true;
      }
    },
    async getDataed() {
      let searchObject = [];
      let data = {
        dataGuid: "70ffff63-fdd9-4da4-b6e1-c77dac92dd96",
        searchObject: JSON.stringify(searchObject),
        bizGuid: "c1e2676c-af57-4441-97e2-8033884c3bb4",
      };
      const res = await ECALoadGridData(data);
      this.contentData3 = res.Data;
    },
  },
};
</script>

<style lang="scss" scoped>
.My {
  height: 100vh;
  overflow: auto;

  .BuildingApplicationLeft {
    height: 88vh;
    overflow-y: auto;
  }

  #shenQing {
    height: 86vh;
    overflow-y: auto;

    // font-family: 黑体;
    ul li {
      padding: 10px;
      height: 100px;
      border-bottom: 1px solid #d2d2d2;
      margin-bottom: 10px;
      padding-top: 4px;
      // border-bottom: 1px solid #d2d2d2;
      background-color: white;
      border-radius: 10px;
      padding: 10px;
      width: 96%;
      margin: 0 auto;
      margin-top: 0.14rem;
      color: black;
      box-shadow: 0 0 0.16rem #e3e3e3;
    }
  }

  #BuildingApplication {

    // font-family: 黑体;
    .SQList {
      width: 100vw;
      height: calc(100vh - 0.88rem);
      overflow-y: auto;
      background: #eee;

      // padding: 0 10px;
      li {
        padding-top: 4px;
        // border-bottom: 1px solid #d2d2d2;
        background-color: white;
        // margin: 14px 10px;
        border-radius: 10px;
        padding: 10px;
        width: 96%;
        margin: 0 auto;
        margin-top: 1rem;
        color: black;
        box-shadow: 0 0 0.16rem #e3e3e3;
      }
    }

    /*padding: 10px;*/

    .bottom {
      clear: both;
      position: fixed;
      bottom: 0;
      // height: 100px;
      width: 100%;
      text-align: center;
      height: 0.88rem;
      background: #ffffff;
      border-top: 1px solid #d2d2d2;

      ul {
        width: 100%;
        height: 100%;
        clear: both;
        overflow: hidden;
        display: flex;
        align-items: center;

        li {
          float: left;
          width: 33.3%;
          font-size: 0.2rem !important;

          img {
            height: 0.35rem;
            margin-bottom: 0.02rem;
          }
        }
      }
    }
  }
}
</style>
